<?php
/**
 * @copyright meila.com
 * @author wangtao5@
 * @name 发布接口
 * @param
 *         $nick = 作用
 *
 *
 */
include('../../__global.php');
class aj_albumfeed_delete extends ml_controller
{
    private $_uid;
    //执行默认检查的参数集合
    protected  $_param_check = array(
            'albumfeed_rid' => array('type'=>ML_DATATYPE_ALNUM, 'is_must'=>true, 'len_limit'=>array('eq'=>ML_RID_LEN)),
    );
    //错误描述
    protected  $_error_msg = array(
            'albumfeed_rid' => 'albumfeed_rid',
    );
    private $_status_array = array('ok'=>1,'del'=>9);
    private $_album_id;
    private $_pic_id;
    /**
     * 初始化参数
     */
    function initParam()
    {
        //必选项
        $this->_option['albumfeed_rid'] = Tool_input::input('albumfeed_rid', 'P', '');
        $this->_uid = $this->__visitor['uid'];
    }
    
    /**
     * @develop_template
     * 检查参数合法性
     */
    function checkParam()
    {
        //检查可写权限
        if(!$this->check_permission(ML_PERMISSION_LOGIN_CANWRITE)) {
            return $this->api_output(ML_RCODE_NOACTIVE);
        }
        $this->check_option();
    }
    
    /**
     * @develop_template
     * 核心业务逻辑
     */
    function main(){
        $result = $this->delete_content();
        if(!$result){
            $this->api_output(ML_RCODE_HACK);
            exit;
        }
        $this->count_deal();
        $this->_private_action_log();
        $this->api_output(ML_RCODE_SUCC);
    }
    /**
     * 添加行为日志
     */
    private function _private_action_log(){
        ml_tool_actionlog::add_other_action($this->_uid ,ML_SINAACTCODE_ALBUM_FEED_DELETE, $this->_option['albumfeed_rid']);
    }
    /**
     * 处理统计数据资源
     */
    function count_deal(){
        $oRedisCount = new ml_model_rdsCount();
        $rs_ufd = $oRedisCount->decrUserfeedcnt($this->_uid);
        $rs_afd = $oRedisCount->decrAlbumfeedCnt($this->_album_id);
        $rs_pafd = $oRedisCount->decrPicAlbumfeedCnt($this->_album_id, $this->_pic_id);
    }
    /**
     * @保存数据
     */
    function delete_content(){
        $oAlbumfeed= new ml_model_album_dbAlbumfeed();
        $rs = $oAlbumfeed->get_by_albumfeed_rid($this->_option['albumfeed_rid']);
        if(!$rs)
            return false;
        $albumfeed = $oAlbumfeed->get_data();
        if(empty($albumfeed))
            return false;
        $status = (int)$albumfeed['status'];
        if($this->_status_array['del'] == $status){
            $this->api_output(ML_RCODE_SUCC);
            exit;
        }
            
        if($this->_uid != $albumfeed['uid'])
            return false;
        
        $this->_album_id = $albumfeed['album_id'];
        $this->_pic_id = $albumfeed['pic_id'];
        $rs = $oAlbumfeed->del_by_albumfeed_rid($this->_option['albumfeed_rid']);
        return $rs;
    }
}

new aj_albumfeed_delete();
